package cn.edu.buaa.sei.jdat.vt.res;

import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.Shape;
import java.io.IOException;

import com.cocotingo.snail.AcceleratedImage;
import com.cocotingo.snail.GraphicsX;
import com.cocotingo.snail.StretchableImage;

public class Resources {
	
	public final static Color COLOR_TEXT_DEFAULT = new Color(245, 245, 245);
	public final static Color COLOR_TEXT_LIGHT = new Color(200, 185, 175);
	public final static Color COLOR_TEXT_GRAY = new Color(150, 135, 125);
	public final static Color COLOR_TEXT_SHADOW = new Color(57, 51, 44);
	public final static Color COLOR_LINE = new Color(81, 77, 72);
	public final static Color COLOR_TEXT_ORANGE = new Color(92, 58, 19);
	public final static Color COLOR_TEXT_ORANGE_SHADOW = new Color(205, 148, 81);
	public final static Color COLOR_TEXT_BROWN = new Color(213, 211, 208);
	public final static Color COLOR_TEXT_BROWN_SHADOW = new Color(63, 55, 47);
	public final static Color COLOR_TEXT_PINK = new Color(68, 19, 34);
	public final static Color COLOR_TEXT_PINK_SHADOW = new Color(192, 124, 143);
	public final static Color COLOR_LIGHT_BACKGROUND = new Color(70, 65, 55);
	
	public final static Color COLOR_GRAPH_ARROW = new Color(255, 208, 81);
	public final static Color COLOR_GRAPH_ARROW_HIGHLIGHTED = new Color(255, 220, 190);
	public final static Color COLOR_GRAPH_ARROW_SELECTED = Color.white;
	
	public final static Font FONT_LABEL = new Font(Font.DIALOG, Font.BOLD, 12);
	public final static Font FONT_BIG_BOLD = new Font(Font.DIALOG, Font.BOLD, 16);
	public final static Font FONT_BIG_PLAIN = new Font(Font.DIALOG, Font.PLAIN, 16);
	public final static Font FONT_DEFAULT = new Font(Font.DIALOG, Font.PLAIN, 12);
	public final static Font FONT_MONO = new Font(Font.MONOSPACED, Font.PLAIN, 12);
	public final static Font FONT_SMALL = new Font(Font.DIALOG, Font.PLAIN, 9);
	
	public static AcceleratedImage IMG_BACKGROUND;
	public static StretchableImage IMG_BUTTON_NORMAL, IMG_BUTTON_PRESSED, IMG_BUTTON_HIGHLIGHTED;
	public static StretchableImage IMG_TEXTBOX_NORMAL;
	public static StretchableImage IMG_DEPTH_BACKGROUND;
	public static StretchableImage IMG_SCROLL_INDICATOR;
	public static StretchableImage IMG_TABBUTTON_LEFT_NORMAL, IMG_TABBUTTON_MIDDLE_NORMAL, IMG_TABBUTTON_RIGHT_NORMAL;
	public static StretchableImage IMG_TABBUTTON_LEFT_HIGHLIGHTED, IMG_TABBUTTON_MIDDLE_HIGHLIGHTED, IMG_TABBUTTON_RIGHT_HIGHLIGHTED;
	public static StretchableImage IMG_TABBUTTON_LEFT_PRESSED, IMG_TABBUTTON_MIDDLE_PRESSED, IMG_TABBUTTON_RIGHT_PRESSED;
	public static StretchableImage IMG_PROGRESSBAR_BACKGROUND, IMG_PROGRESSBAR_FOREGROUND;
	public static StretchableImage IMG_ORANGE_PANEL, IMG_BROWN_PANEL, IMG_PINK_PANEL;
	public static AcceleratedImage IMG_CHECKBOX_NORMAL, IMG_CHECKBOX_HIGHLIGHTED, IMG_CHECKBOX_SELECTED;
	public static AcceleratedImage IMG_RADIOBUTTON_NORMAL, IMG_RADIOBUTTON_HIGHLIGHTED, IMG_RADIOBUTTON_SELECTED;
	public static AcceleratedImage IMG_VALUEBUBBLE;
	
	public static AcceleratedImage ICON_ABSTRACT;
	public static AcceleratedImage ICON_CLASS;
	public static AcceleratedImage ICON_CONSTRUCTOR;
	public static AcceleratedImage ICON_DEFAULT;
	public static AcceleratedImage ICON_ENUM;
	public static AcceleratedImage ICON_FIELD;
	public static AcceleratedImage ICON_FINAL;
	public static AcceleratedImage ICON_INTERFACE;
	public static AcceleratedImage ICON_JAR;
	public static AcceleratedImage ICON_METHOD;
	public static AcceleratedImage ICON_PACKAGE;
	public static AcceleratedImage ICON_PRIVATE;
	public static AcceleratedImage ICON_PROTECTED;
	public static AcceleratedImage ICON_QUESTION;
	public static AcceleratedImage ICON_STATIC;
	
	public static void loadResource(GraphicsConfiguration gc) throws IOException {
		IMG_BACKGROUND = new AcceleratedImage(gc, Resources.class.getResourceAsStream("Background.png"));
		IMG_BUTTON_NORMAL = new StretchableImage(gc, Resources.class.getResourceAsStream("ButtonNormal.png"), 6, 6, 37, 36);
		IMG_BUTTON_PRESSED = new StretchableImage(gc, Resources.class.getResourceAsStream("ButtonPressed.png"), 6, 6, 37, 36);
		IMG_BUTTON_HIGHLIGHTED = new StretchableImage(gc, Resources.class.getResourceAsStream("ButtonHighlighted.png"), 6, 6, 37, 36);
		IMG_TEXTBOX_NORMAL = new StretchableImage(gc, Resources.class.getResourceAsStream("TextBoxNormal.png"), 6, 6, 29, 28);
		IMG_DEPTH_BACKGROUND = new StretchableImage(gc, Resources.class.getResourceAsStream("DepthBackground.png"), 4, 4, 55, 54);
		IMG_SCROLL_INDICATOR = new StretchableImage(gc, Resources.class.getResourceAsStream("ScrollIndicator.png"), 0, 4, 5, 11);
		IMG_TABBUTTON_LEFT_NORMAL = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonLeftNormal.png"), 5, 4, 37, 32);
		IMG_TABBUTTON_MIDDLE_NORMAL = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonMiddleNormal.png"), 1, 1, 36, 35);
		IMG_TABBUTTON_RIGHT_NORMAL = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonRightNormal.png"), 1, 4, 33, 32);
		IMG_TABBUTTON_LEFT_HIGHLIGHTED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonLeftHighlighted.png"), 5, 4, 37, 32);
		IMG_TABBUTTON_MIDDLE_HIGHLIGHTED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonMiddleHighlighted.png"), 1, 1, 36, 35);
		IMG_TABBUTTON_RIGHT_HIGHLIGHTED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonRightHighlighted.png"), 1, 4, 33, 32);
		IMG_TABBUTTON_LEFT_PRESSED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonLeftPressed.png"), 5, 4, 37, 32);
		IMG_TABBUTTON_MIDDLE_PRESSED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonMiddlePressed.png"), 1, 1, 36, 35);
		IMG_TABBUTTON_RIGHT_PRESSED = new StretchableImage(gc, Resources.class.getResourceAsStream("TabButtonRightPressed.png"), 1, 4, 33, 32);
		IMG_PROGRESSBAR_BACKGROUND = new StretchableImage(gc, Resources.class.getResourceAsStream("ProgressBarBackground.png"), 4, 3, 16, 5);
		IMG_PROGRESSBAR_FOREGROUND = new StretchableImage(gc, Resources.class.getResourceAsStream("ProgressBarForeground.png"), 4, 2, 13, 3);
		IMG_ORANGE_PANEL = new StretchableImage(gc, Resources.class.getResourceAsStream("OrangePanel.png"), 5, 4, 45, 22);
		IMG_BROWN_PANEL = new StretchableImage(gc, Resources.class.getResourceAsStream("BrownPanel.png"), 5, 4, 26, 19);
		IMG_PINK_PANEL = new StretchableImage(gc, Resources.class.getResourceAsStream("PinkPanel.png"), 5, 4, 27, 21);
		IMG_CHECKBOX_NORMAL = new AcceleratedImage(gc, Resources.class.getResourceAsStream("CheckBoxNormal.png"));
		IMG_CHECKBOX_HIGHLIGHTED = new AcceleratedImage(gc, Resources.class.getResourceAsStream("CheckBoxHighlighted.png"));
		IMG_CHECKBOX_SELECTED = new AcceleratedImage(gc, Resources.class.getResourceAsStream("CheckBoxSelected.png"));
		IMG_RADIOBUTTON_NORMAL = new AcceleratedImage(gc, Resources.class.getResourceAsStream("RadioButtonNormal.png"));
		IMG_RADIOBUTTON_HIGHLIGHTED = new AcceleratedImage(gc, Resources.class.getResourceAsStream("RadioButtonHighlighted.png"));
		IMG_RADIOBUTTON_SELECTED = new AcceleratedImage(gc, Resources.class.getResourceAsStream("RadioButtonSelected.png"));
		IMG_VALUEBUBBLE = new AcceleratedImage(gc, Resources.class.getResourceAsStream("ValueBubble.png"));
		
		ICON_ABSTRACT = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_abstract.png"));
		ICON_CLASS = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_class.png"));
		ICON_CONSTRUCTOR = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_constructor.png"));
		ICON_DEFAULT = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_default.png"));
		ICON_ENUM = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_enum.png"));
		ICON_FIELD = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_field.png"));
		ICON_FINAL = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_final.png"));
		ICON_INTERFACE = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_interface.png"));
		ICON_JAR = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_jar.png"));
		ICON_METHOD = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_method.png"));
		ICON_PACKAGE = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_package.png"));
		ICON_PRIVATE = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_private.png"));
		ICON_PROTECTED = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_protected.png"));
		ICON_QUESTION = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_question.png"));
		ICON_STATIC = new AcceleratedImage(gc, Resources.class.getResourceAsStream("icons/icon_static.png"));
	}
	
	public static void fillBackground(GraphicsX g, int width, int height) {
		final Shape clipArea = g.getClip();
		g.clipRect(0, 0, width, height);
		for (int x = 0; x < width; x += IMG_BACKGROUND.getWidth())
			for (int y = 0; y < height; y += IMG_BACKGROUND.getHeight()) {
				g.drawImage(IMG_BACKGROUND, x, y);
			}
		g.setClip(clipArea);
	}
	
}
